package com.wanmait.myhouse.managerController;

import com.wanmait.myhouse.dao.CityDaO;
import com.wanmait.myhouse.dao.TypeDAO;
import com.wanmait.myhouse.vo.City;
import com.wanmait.myhouse.vo.Type;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
@Controller
@RequestMapping("manager")
public class ManagerMgAddController {
    @GetMapping("mag")
    @ResponseBody
    public String mag(Type type){
        TypeDAO typeDAO = new TypeDAO();
        Type type1 = typeDAO.FindByName(type);
        if(type1 == null){
            return "1";
        }
            return "0";

    }


    @GetMapping("delete")
    @ResponseBody
    public String delete(Type type){
        TypeDAO typeDAO = new TypeDAO();
        typeDAO.delteById(type);
        return "1";
    }

    @GetMapping("MgAdd")
    public String MgAdd(Model model,Type type){
        TypeDAO typeDAO = new TypeDAO();
        if (type.getTypeName() != null){
            typeDAO.addTypeName(type);
        }
        List<Type> typeList = typeDAO.FindAll();
        model.addAttribute("typeList",typeList);
        return "manager/MgAdd";
    }
}
